package com.wing.member.model.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.enums.IEnum;
import com.fasterxml.jackson.annotation.JsonValue;
import com.wing.mybatis.common.BaseEntity;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * 用户授权
 *
 * @author
 */
@Data
@TableName("mem_member_auth")
public class MemberAuth extends BaseEntity<MemberAuth> {

    public enum Type implements IEnum<Integer> {

        username(0, "用户名"),
        email(1, "邮箱"),
        phone(2, "手机号");

        private int code;
        private String desc;

        Type(int code, String desc){
            this.code = code;
            this.desc = desc;
        }

        @Override
        public Integer getValue() {
            return this.code;
        }

        @JsonValue
        public String getDesc(){
            return this.desc;
        }
    }

    public enum Status implements IEnum<Integer> {

        Enabled(0, "启用"),
        disabled(1, "禁用");

        private int code;
        private String desc;

        Status(int code, String desc){
            this.code = code;
            this.desc = desc;
        }

        @Override
        public Integer getValue() {
            return this.code;
        }

        @JsonValue
        public String getDesc(){
            return this.desc;
        }
    }

    /**
     * 授权类型
     */
    private Type type;

    /**
     * 状态
     */
    private Status status;

    /**
     * 用户ID
     *
     */
    private Long memberId;

    /**
     * 标识
     */
    private String identifier;

    /**
     * 凭证
     */
    private String credential;

    /**
     * 加盐
     */
    private String salt;

    /**
     * 登录时间
     */
    private LocalDateTime loginTime;

    public MemberAuth(){}

    public MemberAuth(Type type, Status status, Long memberId, String identifier, String credential, String salt) {
        this.type = type;
        this.status = status;
        this.memberId = memberId;
        this.identifier = identifier;
        this.credential = credential;
        this.salt = salt;
    }
}
